<?php

class Adept_Template_Tag_Object extends Adept_Template_Tag 
{
    
    protected $ref;
    
    /**
     * @param Adept_Template_Writer_Php $writer
     */
    public function generateBegin($writer) 
    {
        $this->ref = $writer->generateVar();
        $class = $this->getAttributeValue('class');
        
        $writer->writePhp('if (!isset($context[');
        $writer->writePhpLiteral($this->getAttributeValue('id'));
        $writer->writePhp('])) {' . "\n");
        
        $writer->writePhp("{$this->ref} = new {$class}();\n");
        $writer->writePhp('$context[');
        $writer->writePhpLiteral($this->getAttributeValue('id'));
        $writer->writePhp('] = ' . $this->ref . ";\n");
        
        $writer->writePhp("}\n");
    }	
   
    public function getRef() 
    {
    	return $this->ref;
    }	
    
}